﻿using System;
using nRoute.Components;
using nRoute.Components.Composition;

namespace nRoute.Mapping
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
    public abstract class MapResourceBaseAttribute
        : Attribute
    {
        private string _key;

        public MapResourceBaseAttribute() { }

        public MapResourceBaseAttribute(string key)
        {
            // note key can be null
            _key = key;
        }

#region Properties

        protected internal virtual string Key
        {
            get { return _key; }
            set { _key = value; }
        }

        protected internal virtual bool IsDefaultResource
        {
            get { return false; }
        }

#endregion

#region Overridable

        protected internal virtual bool CanInitialize(Type targetType, IResourceCatalog resourceCatalog)
        {
            return true;
        }

        protected internal abstract Type GetResourceType(Type targetType);

        protected internal abstract IResourceLocator GetResourceLocator(Type targetType, ITypeBuilder typeBuilder);

#endregion

    }
}